<?
session_start();
include('../config.php');
include("../classes/connect.php");
require_once('../classes/class.jira.php');

if(isset($_GET['fromdate']) AND isset($_GET['todate'])){
    $type=$_GET['type'];
    if($type==='Open CV')
    {                       
        $type=$action_OpenCV;
    }
    else if($type==='Short Listed')
    {
        $type=$action_ShortList;
       
    }
    else if($type==='Test Called')
    {
        $type=$action_TestCalled;
     
    }
    else if($type==='Rejected')
    {
        $type=$action_Rejected;
       
    }
    else if($type==='Interviewed')
    {
        $type=$action_Interviewed;
          
    }  
    else if($type==='Tested')
    {
        $type=$action_Tested;
    
    }
    else if($type==='Selected')
    {
        $type=$action_Selected;
     
    }
    else if($type==='Offered')
    {
        $type=$action_Offered;
      
    }
    else if($type==='Interviewed Called')
    {
        $type=$action_InterviewCalled;
      
    }
    else if($type==='Final Interview Called')
    {
        $type=$action_FinalInterviewCalled;
      
    }
    else if($type==='Final Interviewed')
    {
      $type=$action_FinalInterviewed;
    }
    else if($type==='Joined')
    {
      $type=$action_Joined;
    }

    
    if($_GET['cat']==='year')
    {
         $arr_out = array();
        $shortlist = "select a.currentAssigneeName,a.id,a.email,a.subject,concat( FROM_UNIXTIME(a.dateReceived)) as receiv,concat( FROM_UNIXTIME(a.modifiedDate)) as modi,a.modifiedBy,a.applicantName,a.priority from trn_emaildetails a 
            where a.deleted='0' AND year(FROM_UNIXTIME(a.modifiedDate))='".$_GET['fromdate']."' AND a.currentStatus='".$type."'";
        $out=mysql_query($shortlist);
         //  $rowShortlist=mysql_fetch_array(mysql_query($shortlist));
         
        $i=0;
        while($rowShortlist=mysql_fetch_array($out))
        { 
               $date1 = strtotime($rowShortlist['receiv']);
        $date2 = time();
        $subTime = $date1 - $date2;
        $y = ($subTime/(60*60*24*365));
        $d = ($subTime/(60*60*24))%365;
        $h = ($subTime/(60*60))%24;
        $m = ($subTime/60)%60;
        $ela=$d.$h.$m;
        $types = explode("-", $ela);
        $ela=$types[1].'d '.$types[2].'h '.$types[3].'m';
            
              $arr=  array(
                    "Id"=> $i + 1,
                    "name" => $rowShortlist['applicantName'],
                    "email" =>$rowShortlist['email'],
                    "subject" => $rowShortlist['subject'],
                    "ReceivedDate" => $rowShortlist['receiv'],
                    "ModifiedDate" => $rowShortlist['modi'],
                    "modifyby" => $rowShortlist['modifiedBy'],
                    "priority" => $rowShortlist['priority'],
                    "rwid" => $rowShortlist['id'],
                    "jiraid" => $rowShortlist['jiraTaskID'],
                    "vcode" => $rowShortlist['vcode'],
                    "cus" => $rowShortlist['currentStatus'],
                    "currentass" => $rowShortlist['currentAssigneeName'],
                  "elapsed" => $ela
                   );
                $arr_out[] = $arr;
                $i++;

        }
       echo json_encode($arr_out);
      //  echo json_encode($out->num_rows);
    }
    else  if($_GET['cat']==='week')
    {

        
        $arr_out = array();
        $shortlist = "select a.currentAssigneeName,a.id,a.email,a.subject,concat( FROM_UNIXTIME(a.dateReceived)) as receiv,concat( FROM_UNIXTIME(a.modifiedDate)) as modi,a.modifiedBy,a.applicantName,a.priority from trn_emaildetails a 
            where a.deleted='0' AND date(FROM_UNIXTIME(a.modifiedDate))>='".$_GET['fromdate']."' AND date(FROM_UNIXTIME(modifiedDate))<='".$_GET['todate']."' AND a.currentStatus='".$type."'";
        $out=mysql_query($shortlist);
         //  $rowShortlist=mysql_fetch_array(mysql_query($shortlist));
         
        $i=0;
        while($rowShortlist=mysql_fetch_array($out))
        { 
                $date1 = strtotime($rowShortlist['receiv']);
        $date2 = time();
        $subTime = $date1 - $date2;
        $y = ($subTime/(60*60*24*365));
        $d = ($subTime/(60*60*24))%365;
        $h = ($subTime/(60*60))%24;
        $m = ($subTime/60)%60;
        $ela=$d.$h.$m;
        $types = explode("-", $ela);
        $ela=$types[1].'d '.$types[2].'h '.$types[3].'m';
            
              $arr=  array(
                    "Id"=> $i + 1,
                    "name" => $rowShortlist['applicantName'],
                    "email" =>$rowShortlist['email'],
                    "subject" => $rowShortlist['subject'],
                    "ReceivedDate" => $rowShortlist['receiv'],
                    "ModifiedDate" => $rowShortlist['modi'],
                    "modifyby" => $rowShortlist['modifiedBy'],
                    "priority" => $rowShortlist['priority'],
                    "rwid" => $rowShortlist['id'],
                    "jiraid" => $rowShortlist['jiraTaskID'],
                    "vcode" => $rowShortlist['vcode'],
                    "cus" => $rowShortlist['currentStatus'],
                  "currentass" => $rowShortlist['currentAssigneeName'],
                  "elapsed" => $ela
                   );
                $arr_out[] = $arr;
                $i++;

        }
        echo json_encode($arr_out);
        //echo json_encode($out->num_rows);
        
        
    }
}
 

?>	